package org.tony.xml.demo;

import org.xml.sax.Attributes;
import org.xml.sax.ContentHandler;
import org.xml.sax.Locator;
import org.xml.sax.SAXException;

public class MyContentHandler implements ContentHandler
{

	private StringBuilder	sb;

	public MyContentHandler()
	{
		sb = new StringBuilder();
	}

	public void setDocumentLocator(Locator locator)
	{
		System.out.println(">>> set document_locator : (lineNumber = " + locator.getLineNumber() + ",columnNumber = "
				+ locator.getColumnNumber() + ",systemId = " + locator.getSystemId() + ",publicId = "
				+ locator.getPublicId() + ")");
	}

	public void startDocument() throws SAXException
	{

	}

	public void endDocument() throws SAXException
	{

	}

	public void startPrefixMapping(String prefix , String uri) throws SAXException
	{

	}

	public void endPrefixMapping(String prefix) throws SAXException
	{

	}

	public void startElement(String uri , String localName , String qName , Attributes atts) throws SAXException
	{
		System.out.println("<localName=" + localName + ">");
		System.out.println("<" + qName + ">");
		StringBuilder sb = new StringBuilder("    ");
		for (int i = 0; i < atts.getLength(); i++)
		{
			sb.append("[" + atts.getQName(i) + "," + atts.getValue(i) + "] ");
		}
		System.out.println(sb.toString());
	}

	public void endElement(String uri , String localName , String qName) throws SAXException
	{

	}

	public void characters(char[] ch , int start , int length) throws SAXException
	{
		sb.append(ch, start, length);
		System.out.println("sb:" + sb);
	}

	public void ignorableWhitespace(char[] ch , int start , int length) throws SAXException
	{

	}

	public void processingInstruction(String target , String data) throws SAXException
	{

	}

	public void skippedEntity(String name) throws SAXException
	{

	}

}
